package com.communal.web.form.cr;

import net.sf.ezmorph.bean.MorphDynaBean;
import net.sf.json.JSONObject;

import com.communal.model.cr.CRElectricity;

/**
 * 
 * @author Created by andrey.kuznetsov <br>
 * @author Last modified by $Author$ <br>
 * @author Last modified on $Date$ at revision $Revision$ <br>
 */
public class CRElectricityForm extends CRForm{

	private final String CURRENT_VALUE = "currentValue";
	private final String PREVIOUS_VALUE = "previousValue";
	private final String TARIF_ID = "tarifId";
	
	private Short currentValue;
	private Short previousValue;
	private Integer tarifId;
	
	
	/**
	 * Constructor from JSON data for {@link CRElectricityForm} <br>
	 * @param p_data - JSON data
	 */
	public CRElectricityForm(Object p_data) {
		super( p_data, true );
		JSONObject jsonObject = JSONObject.fromObject(p_data);
		MorphDynaBean bean = (MorphDynaBean) JSONObject.toBean(jsonObject);
		currentValue = Short.parseShort(bean.get(CURRENT_VALUE).toString());
		previousValue = Short.parseShort(bean.get(PREVIOUS_VALUE).toString());
		tarifId = (Integer) bean.get(TARIF_ID);
	}

	/**
	 * Constructor for {@link CRElectricityForm} from electricity entity <br>
	 * @param p_communalRecord {@link CRElectricity}
	 */
	public CRElectricityForm(CRElectricity p_electricity, String p_monthYear) {
		super( p_electricity, p_monthYear );
		currentValue = p_electricity.getCurrentValue();
		previousValue = p_electricity.getPreviousValue();
		tarifId= p_electricity.getTarif().getId();
	}

	/**
	 * Returns current value of electric counter <br>
	 * @return {@link Short};
	 */
	public Short getCurrentValue() {
		return currentValue;
	}

	/**
	 * Sets current value of electric counter <br>
	 * @param p_currentValue - {@link Short};
	 */
	public void setCurrentValue(Short p_currentValue) {
		currentValue = p_currentValue;
	}

	/**
	 * Returns previous value of electric counter <br>
	 * @return {@link Short};
	 */
	public Short getPreviousValue() {
		return previousValue;
	}

	/**
	 * Sets previous value for electric counter <br>
	 * @param p_previousValue - {@link Short};
	 */
	public void setPreviousValue(Short p_previousValue) {
		previousValue = p_previousValue;
	}

	/**
	 * Returns tarif id <br>
	 * @return {@link Integer};
	 */
	public Integer getTarifId() {
		return tarifId;
	}

	/**
	 * Sets tarif id <br>
	 * @param p_tarifId - {@link Integer};
	 */
	public void setTarifId(Integer p_tarifId) {
		tarifId = p_tarifId;
	}
	
	
}
